﻿Public Class clsGroupJoin
    Dim SecondWait As Integer = 0
    Dim web As WebBrowser
    Dim step_action As String
    Dim ParseHTML As New clsParseHTML


    'TODO CHECK TIMEOUT

    Public Sub New()
        web = New WebBrowser
        web.ScriptErrorsSuppressed = True
        AddHandler web.DocumentCompleted, AddressOf web_DocumentCompleted
    End Sub

    Public Sub JoinGroup(ByVal GroupID As Long)
        OpenSite(GroupID)
    End Sub

    Private Sub OpenSite(ByVal GroupID As Long)
        web.Navigate("https://m.facebook.com/groups/" & GroupID)
    End Sub

    Private Sub web_DocumentCompleted()
        If (frmMain.is_debug = True) Then
            frmDebug.web_debug_joingroup.Document.Write("<html><head><title></title><body>" & web.DocumentText & "</body></html>")
            frmDebug.txt_debug_joingroup.Text = web.DocumentText
        End If
        If (InStr(web.DocumentText, "/a/group/join/?group_id", CompareMethod.Text) > 0) Then
            ParseHTML.SetSubmitByClassname(web, "bj")
        Else
            JoinSuccess()
        End If
    End Sub

    Private Sub JoinSuccess()
        Debug.Print("Join success")
    End Sub

    Private Sub JoinFail()

    End Sub
End Class
